﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Có trứng thực</title>
<meta name="GENERATOR" content="WinCHM">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

</head>

<body>
<P><A 
href="http://vovanhai.wordpress.com/j2ee/java-mail/g%E1%BB%ADi-mail-co-ch%E1%BB%A9ng-th%E1%BB%B1c-trong-java/"><FONT 
face=Courier>http://vovanhai.wordpress.com/j2ee/java-mail/g%E1%BB%ADi-mail-co-ch%E1%BB%A9ng-th%E1%BB%B1c-trong-java/</FONT></A></P>
<P>đã áp cho OEKAKIGOKKO</P>
<P 
style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px 0px 15px; WORD-SPACING: 0px; FONT: 11px/1.5em Verdana, Tahoma, Arial, sans-serif; TEXT-TRANSFORM: none; COLOR: rgb(42,42,42); TEXT-INDENT: 0px; PADDING-TOP: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BACKGROUND-COLOR: rgb(250,252,255); TEXT-ALIGN: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">package 
gmail;</P>
<P 
style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px 0px 15px; WORD-SPACING: 0px; FONT: 11px/1.5em Verdana, Tahoma, Arial, sans-serif; TEXT-TRANSFORM: none; COLOR: rgb(42,42,42); TEXT-INDENT: 0px; PADDING-TOP: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BACKGROUND-COLOR: rgb(250,252,255); TEXT-ALIGN: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">import 
java.util.Date;<BR>import java.util.Properties;</P>
<P 
style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px 0px 15px; WORD-SPACING: 0px; FONT: 11px/1.5em Verdana, Tahoma, Arial, sans-serif; TEXT-TRANSFORM: none; COLOR: rgb(42,42,42); TEXT-INDENT: 0px; PADDING-TOP: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BACKGROUND-COLOR: rgb(250,252,255); TEXT-ALIGN: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">import 
javax.mail.Authenticator;<BR>import javax.mail.Message;<BR>import 
javax.mail.PasswordAuthentication;<BR>import javax.mail.Session;<BR>import 
javax.mail.Transport;<BR>import javax.mail.internet.InternetAddress;<BR>import 
javax.mail.internet.MimeMessage;</P>
<P 
style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px 0px 15px; WORD-SPACING: 0px; FONT: 11px/1.5em Verdana, Tahoma, Arial, sans-serif; TEXT-TRANSFORM: none; COLOR: rgb(42,42,42); TEXT-INDENT: 0px; PADDING-TOP: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BACKGROUND-COLOR: rgb(250,252,255); TEXT-ALIGN: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">public 
class SendMailOK {</P>
<P 
style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px 0px 15px; WORD-SPACING: 0px; FONT: 11px/1.5em Verdana, Tahoma, Arial, sans-serif; TEXT-TRANSFORM: none; COLOR: rgb(42,42,42); TEXT-INDENT: 0px; PADDING-TOP: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BACKGROUND-COLOR: rgb(250,252,255); TEXT-ALIGN: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">public 
static void send(String smtpServer, String to, String from,String psw,<BR>String 
subject, String body) throws Exception{<BR>// 
java.security.Security.addProvider(new 
com.sun.net.ssl.internal.ssl.Provider());<BR>Properties props = 
System.getProperties();<BR>// –<BR>props.put(”mail.smtp.host”, 
smtpServer);<BR>props.put(”mail.smtp.port”, 
“587″);<BR>props.put(”mail.smtp.starttls.enable”,”true”);<BR>final String login 
= from;//”nth001@gmail.com”;//usermail<BR>final String pwd = psw;//”password cua 
ban o day”;<BR>Authenticator pa = null; //default: no authentication<BR>if 
(login != null &amp;&amp; pwd != null) { //authentication 
required?<BR>props.put(”mail.smtp.auth”, “true”);<BR>pa = new Authenticator 
(){<BR>public PasswordAuthentication getPasswordAuthentication() {<BR>return new 
PasswordAuthentication(login, pwd);<BR>}<BR>};<BR>}//else: no 
authentication<BR>Session session = Session.getInstance(props, pa);<BR>// — 
Create a new message –<BR>Message msg = new MimeMessage(session);<BR>// — Set 
the FROM and TO fields –<BR>msg.setFrom(new 
InternetAddress(from));<BR>msg.setRecipients(Message.RecipientType.TO, 
InternetAddress.parse(<BR>to, false));</P>
<P 
style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px 0px 15px; WORD-SPACING: 0px; FONT: 11px/1.5em Verdana, Tahoma, Arial, sans-serif; TEXT-TRANSFORM: none; COLOR: rgb(42,42,42); TEXT-INDENT: 0px; PADDING-TOP: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BACKGROUND-COLOR: rgb(250,252,255); TEXT-ALIGN: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">// 
— Set the subject and body text 
–<BR>msg.setSubject(subject);<BR>msg.setText(body);<BR>// — Set some other 
header information –<BR>msg.setHeader(”X-Mailer”, 
“LOTONtechEmail”);<BR>msg.setSentDate(new Date());<BR>msg.saveChanges();<BR>// — 
Send the message –<BR>Transport.send(msg);<BR>System.out.println(”Message sent 
OK.”);</P>
<P 
style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px 0px 15px; WORD-SPACING: 0px; FONT: 11px/1.5em Verdana, Tahoma, Arial, sans-serif; TEXT-TRANSFORM: none; COLOR: rgb(42,42,42); TEXT-INDENT: 0px; PADDING-TOP: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BACKGROUND-COLOR: rgb(250,252,255); TEXT-ALIGN: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">}<BR>/**<BR>* 
Main method to send a message given on the command line.<BR>*/<BR>public static 
void main(String[] args) {<BR>{<BR>try<BR>{<BR>String 
smtpServer=”smtp.gmail.com”;<BR>String to=”vovanhaiqn@gmail.com”;<BR>String 
from=”vonguyenhamy@gmail.com”;<BR>String subject=”Hello from Java”;<BR>String 
body=”Test using java to send mail.”;<BR>String password=”máº&shy;t kháº©u cá»§a 
báº¡n á»Ÿ Ä‘Ă¢y”;<BR>send(smtpServer, to, from, password, subject, 
body);<BR>System.out.println(”Finish!”);<BR>}<BR>catch (Exception 
ex)<BR>{<BR>System.out.println(”Usage: “+ex.getMessage());<BR>}</P>
<P 
style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px 0px 15px; WORD-SPACING: 0px; FONT: 11px/1.5em Verdana, Tahoma, Arial, sans-serif; TEXT-TRANSFORM: none; COLOR: rgb(42,42,42); TEXT-INDENT: 0px; PADDING-TOP: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BACKGROUND-COLOR: rgb(250,252,255); TEXT-ALIGN: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">}</P>
<P 
style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px 0px 15px; WORD-SPACING: 0px; FONT: 11px/1.5em Verdana, Tahoma, Arial, sans-serif; TEXT-TRANSFORM: none; COLOR: rgb(42,42,42); TEXT-INDENT: 0px; PADDING-TOP: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BACKGROUND-COLOR: rgb(250,252,255); TEXT-ALIGN: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">/**<BR>* 
“send” method to send the message.<BR>*/</P>
<P 
style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px 0px 15px; WORD-SPACING: 0px; FONT: 11px/1.5em Verdana, Tahoma, Arial, sans-serif; TEXT-TRANSFORM: none; COLOR: rgb(42,42,42); TEXT-INDENT: 0px; PADDING-TOP: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BACKGROUND-COLOR: rgb(250,252,255); TEXT-ALIGN: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">}</P>
<P 
style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px 0px 15px; WORD-SPACING: 0px; FONT: 11px/1.5em Verdana, Tahoma, Arial, sans-serif; TEXT-TRANSFORM: none; COLOR: rgb(42,42,42); TEXT-INDENT: 0px; PADDING-TOP: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BACKGROUND-COLOR: rgb(250,252,255); TEXT-ALIGN: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">}</P></body>
</html>
